package org.hegang.design.second.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyClass implements InvocationHandler {

    private Marry marry;

    public void setMarry(Marry marry) {
        this.marry = marry;
    }

    public Object getProxy() {
        return Proxy.newProxyInstance(this.marry.getClass().getClassLoader(), this.marry.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object invoke = method.invoke(marry, args);
        after();
        return invoke;
    }


    private void after() {
        System.out.println("结婚后，收尾款！");
    }

    private void before() {
        System.out.println("结婚前，布置现场！");
    }
}
